import { DataTypes } from 'sequelize'
const seq = require('../db/seq')

const EntModels: any = seq.define('ent', {
  id: {
    autoIncrement: true,
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING(48),
    allowNull: false
  },
  sname: {
    type: DataTypes.STRING(48),
    allowNull: true,
    comment: "简称"
  },
  address: {
    type: DataTypes.STRING(64),
    allowNull: true
  },
  city: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: "城市id",
    references: {
      model: 'region',
      key: 'id'
    }
  },
  province_name: {
    type: DataTypes.STRING(45),
    allowNull: true,
    comment: "省名，由触发器生成"
  },
  city_name: {
    type: DataTypes.STRING(45),
    allowNull: true,
    comment: "城市名，由触发器生成"
  },
  creattime: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    comment: "建立时间，由触发器生成"
  },
  moditime: {
    type: DataTypes.DATEONLY,
    allowNull: true,
    comment: "修改时间，由触发器生成"
  },
  uscc: {
    type: DataTypes.STRING(24),
    allowNull: true,
    comment: "统一社会信用代码"
  },
  introduction: {
    type: DataTypes.STRING(255),
    allowNull: true,
    defaultValue: "无",
    comment: "企业简介"
  }
}, {
  tableName: 'ent',
  hasTrigger: true,
  timestamps: false,
  indexes: [
    {
      name: "PRIMARY",
      unique: true,
      using: "BTREE",
      fields: [
        { name: "id" },
      ]
    },
    {
      name: "ent_ibfk_city_idx",
      using: "BTREE",
      fields: [
        { name: "city" },
      ]
    },
  ]
});

module.exports = EntModels